%---------------------------------------------------------------------------%
%-                                                                         -%
%-                           Document Class                                -%
%-                                                                         -%
%---------------------------------------------------------------------------%
%- Copyright (C) Huangrui Mo <huangrui.mo@gmail.com> 
%- This is free software: you can redistribute it and/or modify it
%- under the terms of the GNU General Public License as published by
%- the Free Software Foundation, either version 3 of the License, or
%- (at your option) any later version.
%---------------------------------------------------------------------------%
%->> Identification
%---------------------------------------------------------------------------%
\NeedsTeXFormat{LaTeX2e}%
\newcommand*\@iflatexlater{\@ifl@t@r\fmtversion}%
\@iflatexlater{2017/01/01}{}{%
    \ClassError{gsuplthesis}{TeXLive/MikTex >= 2017 is required ...}{}%
}
\ProvidesClass{gsuplthesis}[2014/10/01 v1.0 LaTeX document class]%
%---------------------------------------------------------------------------%
%->> Declare options
%---------------------------------------------------------------------------%
%-
%-> Layout
%-
\DeclareOption{oneside}{%
    \PassOptionsToClass{oneside}{ctexbook}%
}
\DeclareOption{twoside}{%
    \PassOptionsToClass{twoside}{ctexbook}%
}
\newif\ifgsupl@print \gsupl@printfalse
\DeclareOption{print}{%
    \PassOptionsToClass{twoside}{ctexbook}%
    \gsupl@printtrue%
}
%-
%-> Language
%-
\newif\ifgsupl@plain \gsupl@plainfalse
\DeclareOption{scheme=plain}{% enable plain writing style
    \PassOptionsToClass{scheme=plain}{ctexbook}%
    \gsupl@plaintrue%
}
%-
%-> Draft version info
%-
\newif\ifgsupl@versioninfo \gsupl@versioninfofalse
\DeclareOption{draftversion}{%
    \gsupl@versioninfotrue%
}
%-
%-> Handle non-implemented options
%-
\DeclareOption*{%
    \PassOptionsToClass{\CurrentOption}{ctexbook}%
}
%-
%-> Terminates all options processing
%-
\ProcessOptions\relax%
%---------------------------------------------------------------------------%
%->> Load class information
%---------------------------------------------------------------------------%
\LoadClass[UTF8,a4paper,zihao=-4]{ctexbook}%
\@ifclasslater{ctexbook}{2017/01/01}{}{%
    \ClassError{gsuplthesis}{ctex >= 2017/01/01 is required ...}{}%
}
%---------------------------------------------------------------------------%
%->> Required packages
%---------------------------------------------------------------------------%
\RequirePackage{ifxetex}% LaTeX engine detection
\RequirePackage{etoolbox}% a toolbox of programming facilities
\newcommand{\gsuplifstreq}{\expandafter\ifstrequal\expandafter}% expansion control
\newcommand{\gsuplifstrbk}{\expandafter\ifblank\expandafter}% expansion control
\RequirePackage{expl3}% LaTeX3 programming environment
\ExplSyntaxOn
\newcommand{\gsupllntotab}[2][1pt]{% convert lines into table lines
    \seq_set_split:NnV \l_tmpa_seq {\\} {#2}
    \clist_set_from_seq:NN \l_tmpa_clist \l_tmpa_seq
    \clist_clear:N \l_tmpb_clist
    \clist_map_inline:Nn \l_tmpa_clist
      {%
        \clist_put_right:Nn \l_tmpb_clist 
          { \ulenhance[#1]{\ulextend{##1}} }
      }
    %\clist_show:N\l_tmpb_clist% show the content of comma list
    \clist_use:Nn \l_tmpb_clist { \\ & }
}
\ExplSyntaxOff
%---------------------------------------------------------------------------%
%->> Load class configuration
%---------------------------------------------------------------------------%
\AtEndOfPackage{% class cfg loaded after package to make preamble commands take effect
    \makeatletter
    \InputIfFileExists{Style/gsuplthesis.cfg}{}{}
    \makeatother
}
%---------------------------------------------------------------------------%
%->> Page layout
%---------------------------------------------------------------------------%
%- use \topmargin insead of \voffset to shift the complete text vertically
%- use \<odd|even>sidemargin insead of \hoffset to shift text horizontally
%- part one -- horizontal widths
%- left side width + textwidth + right side width = paperwidth
%- binding side width + textwidth + nonbinding side width = paperwidth
%- binding side width of [odd, even] page = [left, right] side width
%- left side width of [odd, even] page = 1.0in (fixed) + hoffset + [odd, even]sidemargin
%- assuming A4 paper (210mm x 297mm)
% \setlength{\textwidth}{157mm}% set required text width first
% \setlength{\hoffset}{0mm}% set horizontal offset
% \ifgsupl@print% if print layout enabled
%     \setlength{\oddsidemargin}{8.75mm}% binding side margin
%     \setlength{\evensidemargin}{0mm}% ensure uniform binding side width for printing
% \else
%     \setlength{\oddsidemargin}{8.75mm}% left side margin
%     \setlength{\evensidemargin}{0mm}% ensure uniform left side width for EThesis
% \fi
% \setlength{\marginparwidth}{35pt}% width of margin notes
% \setlength{\marginparsep}{10pt}% width of space between body text and margin notes
% %- part two -- vertical heights
% %- top height + textheight + bottom height = paperheight
% %- top height = 1.0in (fixed) + voffset + topmargin + headheight + headsep 
% \setlength{\textheight}{256mm}% set required text height first
% \setlength{\voffset}{0mm}% set vertical offset
% \setlength{\topmargin}{-24mm}% vertical margin above header
% \setlength{\headheight}{12pt}% header height
% \setlength{\headsep}{17.5pt}% vertical margin between header and body text
\setlength{\footskip}{10.4mm}% vertical margin between footer and body text
%- specifies the amount of space between paragraphs.
\setlength{\parskip}{0.5ex plus 0.25ex minus 0.25ex}
%- line spacing
\linespread{1.6}% line space setting
\raggedbottom% prevent adding vertical white space in strange places
%- default pagestyle is page number at bottom without headers and footers
\pagestyle{plain}
%---------------------------------------------------------------------------%
%->> Style control commands
%---------------------------------------------------------------------------%
%- redefine cleardoublepage to have page style argument
\renewcommand{\cleardoublepage}[1][plain]{%
    \clearpage\if@twoside\ifodd\c@page\else%
    \thispagestyle{#1}%
    \hbox{}\newpage\if@twocolumn\hbox{}\newpage\fi\fi\fi%
}
%- underline
\ifxetex%
    \RequirePackage{ulem}%
\else%
    \RequirePackage{ulem}%
\fi
\newcommand{\ulunify}[1]{\uline{#1}}% unified name
\newcommand{\ulenhance}[2][1pt]{% enhanced underline
    \def\ULthickness{#1}% set thickness
    \setlength{\ULdepth}{0.5em}% set depth
    \expandafter\ulunify\expandafter{#2}% linebreak fix
}
\newcommand{\ulhshift}{-4em}% horizontal shift on underline
\newcommand{\ulextend}[2][350pt]{% extend underline length
    \hbox to #1{\hfill\hspace*{\ulhshift}#2\hfill}}
%---------------------------------------------------------------------------%
%->> Titlepage
%---------------------------------------------------------------------------%
%-
%-> Chinese item commands
%-
\def\gsupl@value@ch@confidential{}
\newcommand{\confidential}[1]{\def\gsupl@value@ch@confidential{#1}}
\def\gsupl@value@ch@orderid{}
\newcommand{\orderid}[1]{\def\gsupl@value@ch@orderid{#1}}
\def\gsupl@value@ch@classid{}
\newcommand{\classid}[1]{\def\gsupl@value@ch@classid{#1}}
\def\gsupl@value@ch@udc{}
\newcommand{\udc}[1]{\def\gsupl@value@ch@udc{#1}}
\def\gsupl@value@ch@schoollogo{}
\newcommand{\schoollogo}[2][]{\def\gsupl@value@ch@schoollogo{\gsuplifstrbk{#1}{\zihao{-2}\bfseries\sffamily #2}{\includegraphics[#1]{#2}}}}
\def\gsupl@value@ch@title{}
\def\gsupl@value@ch@titlemark{}
\renewcommand{\title}[2][\gsupl@value@ch@title]{%
    \def\gsupl@value@ch@title{#2}
    %\def\gsupl@value@ch@titlemark{\MakeUppercase{#1}}}
    \def\gsupl@value@ch@titlemark{#1}}
\def\gsupl@value@ch@comeyear{}
\newcommand{\comeyear}[1]{\def\gsupl@value@ch@comeyear{#1}}
\def\gsupl@value@ch@degreelevel{}
\newcommand{\degreelevel}[1]{\def\gsupl@value@ch@degreelevel{#1}}
\def\gsupl@value@ch@author{}
\renewcommand{\author}[1]{\def\gsupl@value@ch@author{#1}}
\def\gsupl@value@ch@advisor{}
\newcommand{\advisor}[1]{\long\def\gsupl@value@ch@advisor{#1}}
\def\gsupl@value@ch@trueadvisor{}
\newcommand{\trueadvisor}[1]{\long\def\gsupl@value@ch@trueadvisor{#1}}
\def\gsupl@value@ch@advisors{}
\newcommand{\advisors}[1]{\long\def\gsupl@value@ch@advisors{#1}}
\def\gsupl@value@ch@degree{}
\newcommand{\degree}[1]{\def\gsupl@value@ch@degree{#1}}
\def\gsupl@value@ch@degreetype{}
\newcommand{\degreetype}[1]{\def\gsupl@value@ch@degreetype{#1}}
\def\gsupl@value@ch@subject{}
\newcommand{\subject}[1]{\def\gsupl@value@ch@subject{#1}}
\def\gsupl@value@ch@major{}
\newcommand{\major}[1]{\def\gsupl@value@ch@major{#1}}
\def\gsupl@value@ch@institute{}
\newcommand{\institute}[1]{\long\def\gsupl@value@ch@institute{#1}}
\def\gsupl@value@ch@school{}
\newcommand{\school}[1]{\def\gsupl@value@ch@school{#1}}
\def\gsupl@value@ch@orginization{}
\newcommand{\orginization}[1]{\def\gsupl@value@ch@orginization{#1}}
\def\gsupl@value@ch@completedate{}
\newcommand{\completedate}[1]{\def\gsupl@value@ch@completedate{#1}}
\def\gsupl@value@ch@submitdate{}
\newcommand{\submitdate}[1]{\def\gsupl@value@ch@submitdate{#1}}
\def\gsupl@value@ch@studydatefrom{}
\newcommand{\studydatefrom}[1]{\def\gsupl@value@ch@studydatefrom{#1}}
\def\gsupl@value@ch@studydateto{}
\newcommand{\studydateto}[1]{\def\gsupl@value@ch@studydateto{#1}}
\def\gsupl@value@ch@date{}
\renewcommand{\date}[1]{\def\gsupl@value@ch@date{#1}}
\def\gsupl@value@ch@dateyear{}
\newcommand{\dateyear}[1]{\def\gsupl@value@ch@dateyear{#1}}
\def\gsupl@value@ch@datemonth{}
\newcommand{\datemonth}[1]{\def\gsupl@value@ch@datemonth{#1}}
\def\gsupl@value@ch@stunumber{}
\newcommand{\stunumber}[1]{\def\gsupl@value@ch@stunumber{#1}}
%-
%-> English item commands
%-
\def\gsupl@value@en@title{}
\def\gsupl@value@en@titlemark{}
\newcommand{\TITLE}[2][\gsupl@value@en@title]{%
    \def\gsupl@value@en@title{#2}
    %\def\gsupl@value@en@titlemark{\MakeUppercase{#1}}}
    \def\gsupl@value@en@titlemark{#1}}
\def\gsupl@value@en@author{}
\newcommand{\AUTHOR}[1]{\def\gsupl@value@en@author{#1}}
\def\gsupl@value@en@advisor{}
\newcommand{\ADVISOR}[1]{\def\gsupl@value@en@advisor{#1}}
\def\gsupl@value@en@degree{}
\newcommand{\DEGREE}[1]{\edef\gsupl@value@en@degree{\zap@space#1 \@empty}}% expand and remove space
\def\gsupl@value@en@degreetype{}
\newcommand{\DEGREETYPE}[1]{\def\gsupl@value@en@degreetype{#1}}
\def\gsupl@value@en@thesistype{}
\newcommand{\THESISTYPE}[1]{\def\gsupl@value@en@thesistype{#1}}
\def\gsupl@value@en@major{}
\newcommand{\MAJOR}[1]{\def\gsupl@value@en@major{#1}}
\def\gsupl@value@en@institute{}
\newcommand{\INSTITUTE}[1]{\def\gsupl@value@en@institute{#1}}
\def\gsupl@value@en@school{}
\newcommand{\SCHOOL}[1]{\def\gsupl@value@en@school{#1}}
\def\gsupl@value@en@date{}
\newcommand{\DATE}[1]{\def\gsupl@value@en@date{#1}}
%-
%-> Detect and adjust items
%-
\AtEndPreamble{%
    \gsuplifstreq{\gsupl@value@en@degree}{Bachelor}{%
        \def\gsupl@label@ch@school{\gsupl@label@ch@thesis@school}%
        \def\gsupl@label@ch@gac{\gsupl@label@ch@author@gac}%
        \def\gsupl@label@ch@author{\gsupl@label@ch@author@bac}%
        \def\gsupl@label@ch@major{\gsupl@label@ch@major@bac}%
        \def\gsupl@label@ch@institute{\gsupl@label@ch@institute@bac}%
        \def\gsupl@value@en@thesistype{\gsupl@value@en@thesistype@bac}%
        \def\maketitle{\maketitle@xpdc}
        \def\MAKETITLE{\MAKETITLE@xpdc}
    }{%
    \gsuplifstreq{\gsupl@value@en@degree}{Master}{%
        \def\gsupl@label@ch@thesis{\gsupl@label@ch@thesis@mas}%
        \def\gsupl@label@ch@author{\gsupl@label@ch@author@mas}%
        \def\gsupl@label@ch@major{\gsupl@label@ch@major@mas}%
        \def\gsupl@label@ch@institute{\gsupl@label@ch@institute@mas}%
        \def\gsupl@value@en@thesistype{\gsupl@value@en@thesistype@mas}%
        \def\maketitle{\maketitle@xpdc}
        \def\MAKETITLE{\MAKETITLE@xpdc}
    }{%
    \gsuplifstreq{\gsupl@value@en@degree}{Doctor}{%
        \def\gsupl@label@ch@thesis{\gsupl@label@ch@thesis@doc}%
        \def\gsupl@label@ch@author{\gsupl@label@ch@author@doc}%
        \def\gsupl@label@ch@major{\gsupl@label@ch@major@doc}%
        \def\gsupl@label@ch@institute{\gsupl@label@ch@institute@doc}%
        \def\gsupl@value@en@thesistype{\gsupl@value@en@thesistype@doc}%
        \def\maketitle{\maketitle@xpdc}
        \def\MAKETITLE{\MAKETITLE@xpdc}
    }{%
    \gsuplifstreq{\gsupl@value@en@degree}{Postdoctor}{%
        \def\gsupl@label@ch@thesis{\gsupl@label@ch@thesis@pdc}%
        \def\gsupl@label@ch@author{\gsupl@label@ch@author@pdc}%
        \def\gsupl@label@ch@major{\gsupl@label@ch@major@pdc}%
        \def\gsupl@label@ch@institute{\gsupl@label@ch@institute@pdc}%
        \def\gsupl@value@en@thesistype{\gsupl@value@en@thesistype@pdc}%
        \def\maketitle{\maketitle@pdc}
        \def\MAKETITLE{\MAKETITLE@pdc}
    }{%
        \ClassWarning{gsuplthesis}{Invalid value of '\string\DEGREE', please check the spelling}%
    }}}}%
}
%-
%-> Define Chinese style
%-
\newcommand{\maketitle@xpdc}{%
    \cleardoublepage
    \thispagestyle{empty}
    \begin{center}
        \linespread{1.6}
        \zihao{4}

        % \hfill{} \gsuplifstrbk{\gsupl@value@ch@confidential}{}{\gsupl@label@ch@confidential \ulenhance{\ulextend[50pt]{\hspace*{-\ulhshift}\zihao{5}\gsupl@value@ch@confidential}}}

        \vspace*{\stretch{2}}

        % {\gsupl@value@ch@schoollogo}

        {\zihao{-0}\bfseries\sffamily \gsupl@value@ch@school}

        \vspace*{\stretch{2}}

        {\zihao{0}\bfseries {\gsupl@label@ch@thesis@gac}}

        \vspace*{\stretch{4}}

        {\zihao{-2} 题\ 目 \zihao{3} \ulenhance[0.8pt]{\gsupl@value@ch@title}}

        \vspace*{\stretch{3}}

        {
            \zihao{-3} \ulenhance[0.8pt]{\gsupl@value@ch@institute}
            \gsupl@label@ch@institute@bac
            \ulenhance[0.8pt]{\gsupl@value@ch@major}
            专业
            \ulenhance[0.8pt]{\gsupl@value@ch@comeyear}
            级
            \ulenhance[0.8pt]{\gsupl@value@ch@degreelevel}
            班
        }

        \vspace*{\stretch{4}}
        
        \zihao{-2}
        \def\tabcolsep{0pt}
        \def\arraystretch{1.2}
        \begin{tabular}{lcp{6cm}}
            学\quad\quad 号 & \ulenhance[1pt]{\makebox[6cm][c]{\gsupl@value@ch@stunumber}}\\
            \gsupl@label@ch@author & \ulenhance[1pt]{\makebox[6cm][c]{\gsupl@value@ch@author}}\\
            \gsupl@label@ch@advisor & \ulenhance[1pt]{\makebox[6cm][c]{\gsupl@value@ch@advisor}}\\
            实务导师 & \ulenhance[1pt]{\makebox[6cm][c]{\gsupl@value@ch@trueadvisor}}\\
            成\quad\quad 绩 & \ulenhance[1pt]{\makebox[6cm][c]{}}\\
            \gsupl@label@ch@completedate & \ulenhance[1pt]{\makebox[3cm][c]{\gsupl@value@ch@dateyear}} 年
            \ulenhance[1pt]{\makebox[1cm][c]{\gsupl@value@ch@datemonth}} 月 \\
        \end{tabular}


        {\gsupl@value@ch@date}

        \vspace*{\stretch{2}}
    \end{center}
    \clearpage
    \if@twoside
        \thispagestyle{empty}
        \ifgsupl@versioninfo
            \vspace*{\stretch{1}}
            \begin{footnotesize}
                \noindent
                Draft Version (\today)
            \end{footnotesize}
        \fi
        \cleardoublepage[empty]
    \else
        \ifgsupl@versioninfo
            \thispagestyle{empty}
            \vspace*{\stretch{1}}
            \begin{footnotesize}
                \noindent
                Draft Version (\today)
            \end{footnotesize}
            \cleardoublepage[empty]
        \fi
    \fi
    \ifgsupl@print%
        \hypersetup{% set hyperlinks
            hidelinks,% remove link color and border
        }
    \fi
}
\newcommand{\maketitle@pdc}{%
    \cleardoublepage
    \thispagestyle{empty}
    \begin{center}

        \vspace*{30pt}

        \linespread{2.0}
        \zihao{4}

        \makebox[3.0em][s]{\gsupl@label@ch@classid} \ulenhance{\ulextend[6em]{\zihao{5}\gsupl@value@ch@classid}} \hfill{} \gsupl@label@ch@confidential \ulenhance{\ulextend[6em]{\zihao{5}\gsupl@value@ch@confidential}}

        \makebox[3.0em][s]{\gsupl@label@ch@udc} \ulenhance{\ulextend[6em]{\zihao{5}\gsupl@value@ch@udc}} \hfill{} \gsupl@label@ch@orderid \ulenhance{\ulextend[6em]{\zihao{5}\gsupl@value@ch@orderid}}

        \vspace*{\stretch{6}}

        {\ziju{1.5}\gsupl@value@ch@schoollogo}

        \vspace*{\stretch{1}}

        {\zihao{-2}\bfseries\sffamily{\ziju{0.5}\gsupl@label@ch@thesis}}

        \vspace*{\stretch{3}}

        {\zihao{-2} 题目 \zihao{3} \ulenhance[0.5pt]{\gsupl@value@ch@title}}

        \vspace*{\stretch{2.5}}

        \gsupl@value@ch@author

        \vspace*{\stretch{2.5}}

        \def\tabcolsep{1pt}
        \def\arraystretch{1.3}
        \begin{tabular}{l@{\quad}c}
            \gsupl@label@ch@completedate & \ulenhance{\ulextend[200pt]{\gsupl@value@ch@completedate}}\\
            \gsupl@label@ch@submitdate & \ulenhance{\ulextend[200pt]{\gsupl@value@ch@submitdate}}\\
        \end{tabular}

        \vspace*{\stretch{2}}

        \gsupl@value@ch@institute

        \gsupl@value@ch@date

        \vspace*{\stretch{4}}
    \end{center}
    \clearpage
    \if@twoside
      \thispagestyle{empty}
      \cleardoublepage[empty]
    \fi
    \ifgsupl@print%
        \hypersetup{% set hyperlinks
            hidelinks,% remove link color and border
        }
    \fi
}
%-
%-> Define English style
%-
\newcommand{\MAKETITLE@xpdc}{%
    \cleardoublepage
    \thispagestyle{empty}
    \begin{center}
        \linespread{1.6}
        \zihao{4}\bfseries

        \vspace*{50pt}

        {\zihao{-3}\bfseries \ulenhance[1.5pt]{\gsupl@value@en@title}}

        \vspace*{\stretch{3}}

        {\gsupl@label@en@statement}

        {By}

        {\gsupl@value@en@author}

        {\gsupl@value@en@advisor}

        \vspace*{\stretch{3}}

        {\gsupl@value@en@institute}

        \vspace*{\stretch{1}}

        {\gsupl@value@en@date}

        \vspace*{\stretch{3}}
    \end{center}
    \clearpage
    \if@twoside
      \thispagestyle{empty}
      \cleardoublepage[empty]
    \fi
}
\newcommand{\MAKETITLE@pdc}{%
    \cleardoublepage
    \thispagestyle{empty}
    \begin{center}
        \linespread{2.0}
        \zihao{4}

        \vspace*{50pt}

        {\zihao{3} \gsupl@value@ch@title}

        \vspace*{\stretch{3}}

        {\zihao{-3} \gsupl@value@en@title}

        \vspace*{\stretch{3}}

        \def\tabcolsep{1pt}
        \def\arraystretch{1.3}
        \begin{tabular}{l@{\quad}l}
            \makebox[11em][s]{\gsupl@label@ch@author} & \gsupl@value@ch@author\\
            \makebox[11em][s]{\gsupl@label@ch@subject} & \gsupl@value@ch@subject\\
            \makebox[11em][s]{\gsupl@label@ch@major} & \gsupl@value@ch@major\\
        \end{tabular}

        \vspace*{\stretch{3}}

        \gsupl@label@ch@studydatefrom \quad \gsupl@value@ch@studydatefrom

        \gsupl@label@ch@studydateto \quad \gsupl@value@ch@studydateto

        \vspace*{\stretch{3}}

        \gsupl@value@ch@orginization

        \gsupl@value@ch@date

        \vspace*{\stretch{3}}
    \end{center}
    \clearpage
    \if@twoside
      \thispagestyle{empty}
      \cleardoublepage[empty]
    \fi
}
%---------------------------------------------------------------------------%
%->> Author's declaration
%---------------------------------------------------------------------------%
\newcommand{\makedeclaration}{%
    \cleardoublepage
    \thispagestyle{empty}
    {
        \linespread{1.6}
        \zihao{-4}

        \vspace*{2ex}

        \begin{center}
            {\zihao{4}\bfseries\sffamily \gsupl@label@ch@declare@creativity}
        \end{center}

        {\gsupl@value@ch@declare@creativity}

        \vspace*{3ex}

        {\hfill{} {\gsupl@label@ch@declare@author \hspace*{14em}}}

        {\hfill{} {\gsupl@label@ch@declare@date \hspace*{14em}}}

        \vspace*{6ex}

        \begin{center}
            {\zihao{4}\bfseries\sffamily \gsupl@label@ch@declare@rights}
        \end{center}

        {\gsupl@value@ch@declare@rights}

        {\gsupl@value@ch@declare@rule}

        \vspace*{3ex}

        {\hfill{} {\gsupl@label@ch@declare@author \hspace*{10em} \gsupl@label@ch@declare@advisor \hspace*{9em}}}

        {\hfill{} {\gsupl@label@ch@declare@date \hspace*{10em} \gsupl@label@ch@declare@date \hspace*{9em}}}

        \vspace*{3ex}
    }
    \clearpage
    \if@twoside
        \thispagestyle{empty}
        \cleardoublepage[empty]
    \fi
}
%---------------------------------------------------------------------------%
%->> New environments
%---------------------------------------------------------------------------%
%- define chinese keywords
\newcommand{\keywords}[1]{%
    \vspace{\baselineskip}
    \noindent {\bfseries \gsupl@label@ch@keywords} #1}
%- define engish keywords
\newcommand{\KEYWORDS}[1]{%
    \vspace{\baselineskip}
    \noindent {\bfseries \gsupl@label@en@keywords} #1}
%---------------------------------------------------------------------------%
%->> Structure elements
%---------------------------------------------------------------------------%
\ifgsupl@plain%
    \def\contentsname{\gsupl@label@en@tocname}
    \def\listfigurename{\gsupl@label@en@lsfigname}
    \def\listtablename{\gsupl@label@en@lstabname}
    \def\bibname{\gsupl@label@en@bibname}
    \def\refname{\gsupl@label@en@bibname}
    \def\algname{\gsupl@label@en@algname}
    \def\bibetal{\gsupl@label@en@bibetal}
    \def\biband{\gsupl@label@en@biband}
    \def\axiomname{\gsupl@label@en@axiomname}
    \def\theoremname{\gsupl@label@en@theoremname}
    \def\lemmaname{\gsupl@label@en@lemmaname}
    \def\corollaryname{\gsupl@label@en@corollaryname}
    \def\assertionname{\gsupl@label@en@assertionname}
    \def\propositionname{\gsupl@label@en@propositionname}
    \def\conjecturename{\gsupl@label@en@conjecturename}
    \def\definitionname{\gsupl@label@en@definitionname}
    \def\examplename{\gsupl@label@en@examplename}
    \def\remarkname{\gsupl@label@en@remarkname}
    \def\proofname{\gsupl@label@en@proofname}
    \def\@title{\gsupl@value@en@titlemark}
    \def\@author{\gsupl@value@en@author}
\else
    \def\contentsname{\gsupl@label@ch@tocname}
    \def\listfigurename{\gsupl@label@ch@lsfigname}
    \def\listtablename{\gsupl@label@ch@lstabname}
    \def\algname{\gsupl@label@ch@algname}
    \def\bibname{\gsupl@label@ch@bibname}
    \def\refname{\gsupl@label@ch@bibname}
    \def\bibetal{\gsupl@label@ch@bibetal}
    \def\biband{\gsupl@label@ch@biband}
    \def\axiomname{\gsupl@label@ch@axiomname}
    \def\theoremname{\gsupl@label@ch@theoremname}
    \def\lemmaname{\gsupl@label@ch@lemmaname}
    \def\corollaryname{\gsupl@label@ch@corollaryname}
    \def\assertionname{\gsupl@label@ch@assertionname}
    \def\propositionname{\gsupl@label@ch@propositionname}
    \def\conjecturename{\gsupl@label@ch@conjecturename}
    \def\definitionname{\gsupl@label@ch@definitionname}
    \def\examplename{\gsupl@label@ch@examplename}
    \def\remarkname{\gsupl@label@ch@remarkname}
    \def\proofname{\gsupl@label@ch@proofname}
    \def\@title{\gsupl@value@ch@titlemark}
    \def\@author{\gsupl@value@ch@author}
\fi
%---------------------------------------------------------------------------%
%->> Structure layout
%---------------------------------------------------------------------------%
%- chapter
\ctexset {
    chapter = {
        format = \linespread{1.0}\zihao{3}\bfseries\centering,
        nameformat = {},
        titleformat = {},
        number = \chinese{chapter},
        numberformat = ,
        aftername = \quad,
        beforeskip = {0pt},
        afterskip = {16pt},
        pagestyle = plain,
        % clearpage = false  % 添加这一行来禁止新章节强制新页
    }
}
%- section
\ctexset {
    section = {
        format = \linespread{1.0}\zihao{-3}\bfseries\raggedright,
        numberformat = \bfseries,
        aftername = \ ,
        beforeskip = {16pt},
        afterskip = {16pt},
    }
}
%- subsection
\ctexset {
    subsection = {
        format = \linespread{1.0}\zihao{4}\bfseries\raggedright,
        numberformat = \bfseries,
        aftername = \ ,
        beforeskip = {16pt},
        afterskip = {16pt},
    }
}
%- subsubsection
\ctexset {
    subsubsection = {
        format = \linespread{1.0}\zihao{-4}\bfseries\raggedright,
        numberformat = \bfseries,
        aftername = \ ,
        beforeskip = {12pt},
        afterskip = {12pt},
    }
}
%- appendix
\ctexset {
    appendix = {
        numbering = true,
        number = \rmfamily\Alph{chapter},
    }
}
%---------------------------------------------------------------------------%
%->> Configure table of contents
%---------------------------------------------------------------------------%
%- the table of contents is specified by defining \l@chapter, \l@section, ...
%- most commands are then defined with the \@dottedtocline:
%- \@dottedtocline{⟨level⟩}{⟨indent⟩}{⟨numwidth⟩}{⟨title⟩}{⟨page⟩}
%- ⟨level⟩    an entry is produced only if ⟨level⟩ <= value of the tocdepth counter
%-            note, \chapter is level 0, \section is level 1, etc
%- ⟨indent⟩   indentation from the outer left margin of the start of the contents line
%- ⟨numwidth⟩ width of a box in which the section number is to go
%- <title>    title
%- <page>     page number

%- parameters for spacing and length in toc
\def\@dotsep{0.4mu}% separation between dots in mu units
\def\@pnumwidth{1em}% width of a box in which the page number is put
\def\@tocrmarg{2em}% right margin for multiple line entries, \@tocrmarg ≥ \@pnumwidth
\def\@chaptervspace{1ex}% vertical space between chapter titles

%- redefine dottedtocline from classes.dtx and latex.ltx
\renewcommand*{\@dottedtocline}[5]{% [<level>,<indent>,<numwidth>,<title>,<page>]
    \ifnum #1>\c@tocdepth \else
        \vskip 1.2ex % \z@ \@plus.2\p@
        {\leftskip #2\relax \rightskip \@tocrmarg \parfillskip -\rightskip
        \parindent #2\relax\@afterindenttrue
        \interlinepenalty\@M
        \leavevmode \zihao{-4}
        \@tempdima #3\relax
        \advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip
        {#4}\nobreak
        \leaders\hbox{$\m@th\mkern \@dotsep \cdot\mkern \@dotsep$}\hfill
        \nobreak
        \hb@xt@\@pnumwidth{\hfil\normalfont \normalcolor #5}%
        \par\penalty\@highpenalty}%
    \fi
}
%- redefine l@part from book.cls to add dotted toc line
\renewcommand*{\l@part}[2]{% [<title>,<page>]
    \ifnum \c@tocdepth >-2\relax
        \addpenalty{-\@highpenalty}%
        \addvspace{2.25em \@plus\p@}%
        \setlength\@tempdima{3em}%
        \begingroup
            \parindent \z@ \rightskip \@pnumwidth
            \parfillskip -\@pnumwidth
            {\leavevmode
            \zihao{-4} #1
            \leaders\hbox{$\m@th\mkern \@dotsep \cdot\mkern \@dotsep$}% add dotted toc line
            \hfil \hb@xt@\@pnumwidth{\hss #2}}\par
            \nobreak
            \global\@nobreaktrue
            \everypar{\global\@nobreakfalse\everypar{}}%
        \endgroup
    \fi
}
%- redefine l@chapter from book.cls to add dotted toc line
\renewcommand*{\l@chapter}[2]{% [<title>,<page>]
    \ifnum \c@tocdepth >\m@ne
        \addpenalty{-\@highpenalty}%
        \vskip \@chaptervspace \@plus\p@
        \setlength\@tempdima{1.5em}%
        \begingroup
            \parindent \z@ \rightskip \@pnumwidth
            \parfillskip -\@pnumwidth
            \leavevmode \bfseries\zihao{-4}
            \advance\leftskip\@tempdima
            \hskip -\leftskip
            #1\nobreak
            \leaders\hbox to 0.33em{\hfil$\scalebox{0.8}{\textperiodcentered}$\hfil}% 加粗目录点线% add dotted toc line
            \hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
            \penalty\@highpenalty
        \endgroup
    \fi
}
%- redefine indentation for others
\renewcommand*\l@section{\@dottedtocline{1}{1em}{1em}}
\renewcommand*\l@subsection{\@dottedtocline{2}{2em}{1em}}
\renewcommand*\l@subsubsection{\@dottedtocline{3}{3em}{1em}}
\renewcommand*\l@paragraph{\@dottedtocline{4}{4em}{4.8em}}
\renewcommand*\l@subparagraph{\@dottedtocline{5}{5em}{5.8em}}
\renewcommand*\l@figure{\@dottedtocline{1}{1em}{1.8em}}
\renewcommand*\l@table{\@dottedtocline{1}{1em}{1.8em}}
%---------------------------------------------------------------------------%
\endinput

